from page.base_page import BasePage
from appium.webdriver.common.mobileby import By

class LoginPage(BasePage):

    #定位器
    input_locator = (By.XPATH, '//android.widget.Textview[contains')
    btn_locator = (By.ID, 'com.gfeng.daydaycook:id/verifyTv')
    password_locator = (By.ID, "com.gfeng.daydaycook:id/pwdEdit")
    btn_login_locator = (By.ID, "com.gfeng.daydaycook:id/goButton")
    back_locator = (By.ID, "com.gfeng.daydaycook:id/back")

    #操作方法
    #输入手机号
    def click_input(self,driver):
        self.driver.find_elemnet(*self.input_locator).click()
        self.driver.find_elemnet(*self.input_locator).send_keys(driver)

    def click_btn(self):
        self.driver.find_elemnet(*self.btn_locator).click()  #点击获取验证码

    # 点击验证码框
    def click_password(self, driver):
        self.driver.find_elemnet(*self.password_locator).click()
        self.driver.find_elemnet(*self.password_locator).send_keys(driver)

    # 点击登录按钮
    def btn_login(self):
        self.driver.find_elemnet(*self.btn_login_locator).click()

    # 点击返回
    def back(self):
        self.driver.find_elemnet(*self.back_locator).click()

    def login(self, sjh, password):
        self.click_input(sjh)
        self.click_password(password)
        self.btn_login()
        self.back()